//
//  DYResponse.m
//  TestGizWits
//
//  Created by JM on 15/11/7.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "DYResponse.h"
#import <objc/runtime.h>
@implementation DYResponse

+ (instancetype) response {
    return [[[self class] alloc] init];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _responseDic = [NSDictionary dictionary];
    }
    return self;
}

- (void)print {
    //对真实类的成员进行打印。todo
    NSLog(@"DYResponse:%@",[self description]);
}

- (NSString *)description {
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:self.responseDic forKey:@"responseDic"];
    unsigned int outCount, i;
    objc_property_t * properties = class_copyPropertyList([self class], &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        if (propertyName && [[propertyName substringToIndex:3] isEqualToString:@"DY_"]) {
            id propertyValue = [self valueForKey:(NSString *)propertyName];
            if (!propertyValue){
                propertyValue = @"null";
            }
             [dic setObject:propertyValue forKey:propertyName];

        }
    }
    free(properties);

     return [NSString stringWithFormat:@"返回的DYResponse: %@",dic];//对真实类的成员进行打印。todo
}
@end
